package persistence;

import java.io.FileInputStream;
import java.util.Properties;

import persistence.util.ConnectionProvider;

public class DAOFactoryJdbcImplBase {
	/* for access to properties by JdbcDAOImpls*/
	public static Properties daoProperties;
	
	public DAOFactoryJdbcImplBase() {
		
	}
	
	public DAOFactoryJdbcImplBase(String connectionPropertiesFile, ConnectionProvider fallbackProvider) {
		ConnectionProvider conProvider = null;
		try {
			daoProperties = new Properties();
			daoProperties.load(new FileInputStream(connectionPropertiesFile));
			String connectionProviderImpl = daoProperties.getProperty("jdbc.impl.connection-provider");
			Class connectionProviderImplClass = Class.forName(connectionProviderImpl);
			conProvider = (ConnectionProvider)connectionProviderImplClass.newInstance();
		}
		catch (Exception ex) {
			//load default implementation
			conProvider = fallbackProvider;
			//TODO: log that the connection provider impl couldn't be loaded from file			
		}
		JdbcDAOBase.setConProvider(conProvider);
	}

}
